// packageA/yiyishipin/yiyishipin.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    VideoList: [],//视频列表
    // IsPlay:0,//是否播放过
    video_data: {}, //要播放的视频对象
    fullScreen: false, //视频是否全屏
    recommendListArr: [],
  },

  // 请求视频数据
  GetVideo() {
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetStudyVideo&UID=" + this.data.uid),
      success: (res) => {
        console.log(JSON.parse(baseJs.decryUrl(res.data)));
        var res = JSON.parse(baseJs.decryUrl(res.data));
        if (res.ResultFlag) {
          this.setData({
            VideoList: res.ResultData,
            recommendListArr:res.ResultData
          })
        } else {
          wx.showToast({
            title: "error",
          })
        }
      }
    })
  },
  // 点击播放视频
  SeeVideo(e) {
    console.log("播放视频");
    for (let i = 0; i < this.data.recommendListArr.length; i++) {
      if (this.data.recommendListArr[i].activityid === e.currentTarget.id) {
        var temprecommendList = this.data.recommendListArr[i]
      }
    }
    this.setData({
      video_data: temprecommendList,
      // IsPlay:1
    })
    var videoContext = wx.createVideoContext('myvideo', this);
    videoContext.requestFullScreen();
    this.setData({
      fullScreen: true
    })
  },

  // 播放结束时
  closeVideo() {
    var videoContext = wx.createVideoContext('myvideo', this);
    videoContext.exitFullScreen();
    this.setData({
      fullScreen:false
    })
  },

  // 播放视频进入/退出全屏时
  fullScreenn(e){
    console.log(e);
    if(!e.detail.fullScreen){
    this.setData({
      fullScreen:false
    })
  }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      uid: wx.getStorageSync('uid')
    })
    // 请求视频数据
    this.GetVideo()
  },

})